package com.gjw.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gjw.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {


    @Autowired
//    @Qualifier("redisTemplate")
    RedisTemplate redisTemplate;

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @GetMapping("/test")
    public Object test(){
//        String user = (String) redisTemplate.opsForValue().get("user2");
//        System.out.println(user);
//        User user1 = JSONObject.parseObject(user, User.class);
//        System.out.println(user1);
        String user = stringRedisTemplate.opsForValue().get("user2");
        System.out.println(user);
        String parse = JSON.parse(user).toString();
        System.out.println(parse);

        User user1 = JSONObject.parseObject(parse, User.class);
        System.out.println(user1);
        return user1;
    }
}
